package com.vastcom.tyauthcenter.tools;

import org.apache.commons.lang.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Date;
import java.util.UUID;
import java.util.logging.Logger;

public class Tools {

    /**
     * 生成32个字符长度的UUID
     *
     * @author aJiel
     * @return String
     */
    public static String newUUID() {
        String uuid = UUID.randomUUID().toString();
        uuid = uuid.replace("-", "");
        return uuid;
    }

    /**
     * 验证字符串是否为null和"",满足返回true，不满足返回false
     *
     * @author aJie
     * @param str
     * @return boolean
     */
    public static boolean isNullOrSpace(String str) {
        return null == str || "".equals(str) ? true : false;
    }


    public static Timestamp getTimestampAfterOneminute(){
        return new Timestamp(new Date().getTime()+(1000*60));
    }

    public static String getIpAddr(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        if ("0:0:0:0:0:0:0:1".equals(ip)) {
            ip = "127.0.0.1";
        }
        if (ip.split(",").length > 1) {
            ip = ip.split(",")[0];
        }
        return ip;

        }




    }




